﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Touchscreen
{
    public class FilmManager
    {
        List<Film> Films;
        public List<Film> GetUpComingFlims()
        {
            Films = new List<Film>();

            BioscoopMontiwaagEntities database = new BioscoopMontiwaagEntities();

            var films = from f in database.film
                        where f.status == "draait"
                        orderby f.voorstelling.FirstOrDefault().datumtijd
                        select f;
            foreach (var f in films)
            {
                Film film = new Film(f.naam,
                    f.voorstelling.Single().datumtijd,
                    f.voorstelling.Single().zaal_nummer,
                    f.gesprokentaal,
                    f.ondertiteling,
                    f.ondertiteling,
                    f.poster,
                    f.C3d);
                Films.Add(film);
            }

            #region Oude meuk

            //Film film1 = new Film(2, "Gulliver's Travels", new DateTime(2000, 1, 1, 11, 50, 0), 3,
            //    "NL", "NL", "JAJAJAJA", "gulliverstravels4.jpg");

            //Film film2 = new Film(1, "Black Swan", new DateTime(2000, 1, 1, 12, 0, 0), 1,
            //    "EN", "NL", "NENENENE", "blackswan3.jpg");

            //Film film3 = new Film(3, "Sonny Boy", new DateTime(2000, 1, 1, 12, 10, 0), 2 ,
            //    "FR", "NL", "JAJAJAJA", "sonnyboy1.jpg");

            //Film film4 = new Film(4, "The Tourist", new DateTime(2000, 1, 1, 13, 10, 0), 5,
            //    "DE", "NL", "JAJAJAJA", "tourist2.jpg");

            //Film film5 = new Film(5, "Tron: Legacy", new DateTime(2000, 1, 1, 14, 0, 0), 4,
            //    "ES", "NL", "JAJAJAJA", "tronlegacy10.jpg");

            //Films.Add(film1);
            //Films.Add(film2);
            //Films.Add(film3);
            //Films.Add(film4);
            //Films.Add(film5);
            #endregion

            return Films;
        }

        public Film GetFilmByFilmName(string filmName)
        {
            Films = GetUpComingFlims();
            var films = from f in Films
                        where f.title == filmName
                       select f;

            Film film = new Film(films.FirstOrDefault().title,
                                    films.FirstOrDefault().startTime,
                                    films.FirstOrDefault().room,
                                    films.FirstOrDefault().language,
                                    films.FirstOrDefault().subtitles,
                                    films.FirstOrDefault().description,
                                    films.FirstOrDefault().image,
                                    films.FirstOrDefault().dried);            
            return film;
        }
    }
}